using System.Linq;
using Castle.DynamicProxy;
using Framework.Core;
using Framework.Core.Cache;

namespace Framework.Remoting.Client
{
    public class ServiceClientCacheFactory : ServiceClientFactory
    {
        private readonly IStorage storage;

        public ServiceClientCacheFactory(IStorage storage, IWcfInterceptorFactory wcfInterceptorFactory)
            : base(wcfInterceptorFactory)
        {
            this.storage = storage;
        }

        protected override IInterceptor[] GetInterceptors<T>(EnvMode envMode)
        {
            return new[]
                {
                    new CacheInterceptor(new CacheKeyBuilder(new HashProviderForLegacy()), storage),
                    base.GetInterceptors<T>(envMode).First()
                };
        }
    }
}